
/**
 * 
 * @param {*} success   数据库连接成功的回调函数 
 * @param {*} error     数据库连接失败的回调函数
 */
module.exports = function(success,error){
    const mongoose = require('mongoose');
    const {DBHOST, DBNAME, DBPORT} = require('../config/config');


    mongoose.connect(`mongodb://${DBHOST}:${DBPORT}/${DBNAME}`);
    
    //设置strictQuery为true
    mongoose.set('strictQuery',true);
    
    
    mongoose.connection.on('open',()=>{
        success();
    })
    
    mongoose.connection.on('error',()=>{
        error();
    })
    
    mongoose.connection.on('close',()=>{
        console.log('连接关闭')
    })
    
    // //关闭mongoDb的连接  setTimeout是node.js的全局函数
    // setTimeout(()=>{
    //     mongoose.disconnect();
    // },2000)
}

